import 'package:fish_redux/fish_redux.dart';

import 'action.dart';
import 'state.dart';

Reducer<LoginState> buildReducer() {
  return asReducer(
    <Object, Reducer<LoginState>>{
      LoginAction.countDown: _countDown,
      LoginAction.input: _input,
      LoginAction.selectGander: _selectGander,
    },
  );
}

LoginState _countDown(LoginState state, Action action) {
  final LoginState newState = state.clone()..counter = action.payload;
  return newState;
}

LoginState _selectGander(LoginState state, Action action) {
  return state.clone()..ganderValue = action.payload;
}

LoginState _input(LoginState state, Action action) {
  final LoginState newState = state.clone();
  Map<String, String> payload = action.payload;
  payload.forEach((k, v) {
    switch (k) {
      case 'password':
        newState.password = v;
        break;
      case 'code':
        newState.code = v;
        break;
    }
  });
  return newState;
}
